package com.pijunn.label

import com.pijunn.common.enums.LabelType;
import com.pijunn.users.AppUser;

class Label {

    static constraints = {
		serialNumber(blank: false, validator: {val, obj -> 
			if (val < 10000000)
				return 'label.serialNumber.size.toosmall'
			else if(val > 99999999)
				return 'label.serialNumber.size.toobig'
		})
		registrationDate(nullable: true)
		creationDate()
		createdByUserName(blank: false)
		type(blank: false)
		registeredTo(nullable: true)
    }
	
	Integer serialNumber
	Date registrationDate
	Date creationDate
	String createdByUserName
	LabelType type
	boolean assigned
	AppUser registeredTo
	
	static hasMany = [item: LabeledItem]
	
	static fetchMode = [item: 'eager']
	
	String toString() {
		"${serialNumber} (${type})"
	}
}
